/* Arduino SdFat Library
 * Copyright (C) 2010 by William Greiman
 *
 * This file is part of the Arduino SdFat Library
 *
 * This Library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This Library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with the Arduino SdFat Library.  If not, see
 * <http://www.gnu.org/licenses/>.
 */
#if defined(__arm__) // Arduino Due Board follows

#ifndef Sd2PinMap_h
#define Sd2PinMap_h

#include <Arduino.h>

uint8_t const SS_PIN = SS;
uint8_t const MOSI_PIN = MOSI;
uint8_t const MISO_PIN = MISO;
uint8_t const SCK_PIN = SCK;

#endif // Sd2PinMap_h

#elif defined(__AVR__) // Other AVR based Boards follows

// Warning this file was generated by a program.
#ifndef Sd2PinMap_h
#define Sd2PinMap_h
#include <avr/io.h>

//------------------------------------------------------------------------------
/** struct for mapping digital pins */
struct pin_map_t {
  volatile uint8_t* ddr;
  volatile uint8_t* pin;
  volatile uint8_t* port;
  uint8_t bit;
};

//Pin definitions for ATmega64/128/1281/2561
#if defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__) 


// Two Wire (aka I2C) ports
uint8_t const SDA_PIN = 18;
uint8_t const SCL_PIN = 19;

// SPI port
uint8_t const SS_PIN = 8;
uint8_t const SCK_PIN = 9;			
uint8_t const MOSI_PIN = 10;	
uint8_t const MISO_PIN = 11;	

static const pin_map_t digitalPinMap[] = {
  {&DDRE, &PINE, &PORTE, 0},  // E0  0
  {&DDRE, &PINE, &PORTE, 1},  // E1  1
  {&DDRE, &PINE, &PORTE, 2},  // E2  2
  {&DDRE, &PINE, &PORTE, 3},  // E3  3
  {&DDRE, &PINE, &PORTE, 4},  // E4  4
  {&DDRE, &PINE, &PORTE, 5},  // E5  5
  {&DDRE, &PINE, &PORTE, 6},  // E6  6
  {&DDRE, &PINE, &PORTE, 7},  // E7  7
  {&DDRB, &PINB, &PORTB, 0},  // B0  8
  {&DDRB, &PINB, &PORTB, 1},  // B1  9
  {&DDRB, &PINB, &PORTB, 2},  // B2  10
  {&DDRB, &PINB, &PORTB, 3},  // B3  11
  {&DDRB, &PINB, &PORTB, 4},  // B4  12
  {&DDRB, &PINB, &PORTB, 5},  // B5  13
  {&DDRB, &PINB, &PORTB, 6},  // B6  14
  {&DDRB, &PINB, &PORTB, 7},  // B7  15
  {&DDRG, &PING, &PORTG, 3},  // G4  16
  {&DDRG, &PING, &PORTG, 4},  // G4  17
  {&DDRD, &PIND, &PORTD, 0},  // D0  18
  {&DDRD, &PIND, &PORTD, 1},  // D1  19
  {&DDRD, &PIND, &PORTD, 2},  // D2  20
  {&DDRD, &PIND, &PORTD, 3},  // D3  21
  {&DDRD, &PIND, &PORTD, 4},  // D4  22
  {&DDRD, &PIND, &PORTD, 5},  // D5  23
  {&DDRD, &PIND, &PORTD, 6},  // D6  24
  {&DDRD, &PIND, &PORTD, 7},  // D7  25
  {&DDRG, &PING, &PORTG, 0},  // G0  26
  {&DDRG, &PING, &PORTG, 1},  // G1  27
  {&DDRC, &PINC, &PORTC, 0},  // C0  28
  {&DDRC, &PINC, &PORTC, 1},  // C1  29
  {&DDRC, &PINC, &PORTC, 2},  // C2  30
  {&DDRC, &PINC, &PORTC, 3},  // C3  31
  {&DDRC, &PINC, &PORTC, 4},  // C4  32
  {&DDRC, &PINC, &PORTC, 5},  // C5  33
  {&DDRC, &PINC, &PORTC, 6},  // C6  34
  {&DDRC, &PINC, &PORTC, 7},  // C7  35
  {&DDRG, &PING, &PORTG, 2},  // G2  36
  {&DDRA, &PINA, &PORTA, 7},  // A7  37
  {&DDRA, &PINA, &PORTA, 6},  // A6  38
  {&DDRA, &PINA, &PORTA, 5},  // A5  39
  {&DDRA, &PINA, &PORTA, 4},  // A4  40
  {&DDRA, &PINA, &PORTA, 3},  // A3  41
  {&DDRA, &PINA, &PORTA, 2},  // A2  42
  {&DDRA, &PINA, &PORTA, 1},  // A1  43
  {&DDRA, &PINA, &PORTA, 0},  // A0  44
  {&DDRF, &PINF, &PORTF, 0},  // F0  45
  {&DDRF, &PINF, &PORTF, 1},  // F1  46
  {&DDRF, &PINF, &PORTF, 2},  // F2  47
  {&DDRF, &PINF, &PORTF, 3},  // F3  48
  {&DDRF, &PINF, &PORTF, 4},  // F4  49
  {&DDRF, &PINF, &PORTF, 5},  // F5  50
  {&DDRF, &PINF, &PORTF, 6},  // F6  51
  {&DDRF, &PINF, &PORTF, 7}   // F7  52
};

//Arduino MEGA compatible pin definitions for ATmega640/1280/2560
#elif defined(__AVR_ATmega640__) ||defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) && defined(MEGA_PINOUT)

// Two Wire (aka I2C) ports
uint8_t const SDA_PIN = 20;
uint8_t const SCL_PIN = 21;

// SPI port
uint8_t const SS_PIN = 53;
uint8_t const MOSI_PIN = 51;
uint8_t const MISO_PIN = 50;
uint8_t const SCK_PIN = 52;

static const pin_map_t digitalPinMap[] = {
  {&DDRE, &PINE, &PORTE, 0},  // E0  0
  {&DDRE, &PINE, &PORTE, 1},  // E1  1
  {&DDRE, &PINE, &PORTE, 4},  // E4  2
  {&DDRE, &PINE, &PORTE, 5},  // E5  3
  {&DDRG, &PING, &PORTG, 5},  // G5  4
  {&DDRE, &PINE, &PORTE, 3},  // E3  5
  {&DDRH, &PINH, &PORTH, 3},  // H3  6
  {&DDRH, &PINH, &PORTH, 4},  // H4  7
  {&DDRH, &PINH, &PORTH, 5},  // H5  8
  {&DDRH, &PINH, &PORTH, 6},  // H6  9
  {&DDRB, &PINB, &PORTB, 4},  // B4 10
  {&DDRB, &PINB, &PORTB, 5},  // B5 11
  {&DDRB, &PINB, &PORTB, 6},  // B6 12
  {&DDRB, &PINB, &PORTB, 7},  // B7 13
  {&DDRJ, &PINJ, &PORTJ, 1},  // J1 14
  {&DDRJ, &PINJ, &PORTJ, 0},  // J0 15
  {&DDRH, &PINH, &PORTH, 1},  // H1 16
  {&DDRH, &PINH, &PORTH, 0},  // H0 17
  {&DDRD, &PIND, &PORTD, 3},  // D3 18
  {&DDRD, &PIND, &PORTD, 2},  // D2 19
  {&DDRD, &PIND, &PORTD, 1},  // D1 20
  {&DDRD, &PIND, &PORTD, 0},  // D0 21
  {&DDRA, &PINA, &PORTA, 0},  // A0 22
  {&DDRA, &PINA, &PORTA, 1},  // A1 23
  {&DDRA, &PINA, &PORTA, 2},  // A2 24
  {&DDRA, &PINA, &PORTA, 3},  // A3 25
  {&DDRA, &PINA, &PORTA, 4},  // A4 26
  {&DDRA, &PINA, &PORTA, 5},  // A5 27
  {&DDRA, &PINA, &PORTA, 6},  // A6 28
  {&DDRA, &PINA, &PORTA, 7},  // A7 29
  {&DDRC, &PINC, &PORTC, 7},  // C7 30
  {&DDRC, &PINC, &PORTC, 6},  // C6 31
  {&DDRC, &PINC, &PORTC, 5},  // C5 32
  {&DDRC, &PINC, &PORTC, 4},  // C4 33
  {&DDRC, &PINC, &PORTC, 3},  // C3 34
  {&DDRC, &PINC, &PORTC, 2},  // C2 35
  {&DDRC, &PINC, &PORTC, 1},  // C1 36
  {&DDRC, &PINC, &PORTC, 0},  // C0 37
  {&DDRD, &PIND, &PORTD, 7},  // D7 38
  {&DDRG, &PING, &PORTG, 2},  // G2 39
  {&DDRG, &PING, &PORTG, 1},  // G1 40
  {&DDRG, &PING, &PORTG, 0},  // G0 41
  {&DDRL, &PINL, &PORTL, 7},  // L7 42
  {&DDRL, &PINL, &PORTL, 6},  // L6 43
  {&DDRL, &PINL, &PORTL, 5},  // L5 44
  {&DDRL, &PINL, &PORTL, 4},  // L4 45
  {&DDRL, &PINL, &PORTL, 3},  // L3 46
  {&DDRL, &PINL, &PORTL, 2},  // L2 47
  {&DDRL, &PINL, &PORTL, 1},  // L1 48
  {&DDRL, &PINL, &PORTL, 0},  // L0 49
  {&DDRB, &PINB, &PORTB, 3},  // B3 50
  {&DDRB, &PINB, &PORTB, 2},  // B2 51
  {&DDRB, &PINB, &PORTB, 1},  // B1 52
  {&DDRB, &PINB, &PORTB, 0},  // B0 53
  {&DDRF, &PINF, &PORTF, 0},  // F0 54
  {&DDRF, &PINF, &PORTF, 1},  // F1 55
  {&DDRF, &PINF, &PORTF, 2},  // F2 56
  {&DDRF, &PINF, &PORTF, 3},  // F3 57
  {&DDRF, &PINF, &PORTF, 4},  // F4 58
  {&DDRF, &PINF, &PORTF, 5},  // F5 59
  {&DDRF, &PINF, &PORTF, 6},  // F6 60
  {&DDRF, &PINF, &PORTF, 7},  // F7 61
  {&DDRK, &PINK, &PORTK, 0},  // K0 62
  {&DDRK, &PINK, &PORTK, 1},  // K1 63
  {&DDRK, &PINK, &PORTK, 2},  // K2 64
  {&DDRK, &PINK, &PORTK, 3},  // K3 65
  {&DDRK, &PINK, &PORTK, 4},  // K4 66
  {&DDRK, &PINK, &PORTK, 5},  // K5 67
  {&DDRK, &PINK, &PORTK, 6},  // K6 68
  {&DDRK, &PINK, &PORTK, 7}   // K7 69
};
  

//"AVR" compatible pin definitions for ATmega640/1280/2560
#elif defined(__AVR_ATmega640__) ||defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) && defined(MEGA_AVR_PINOUT)

// Two Wire (aka I2C) ports
uint8_t const SDA_PIN = 35;
uint8_t const SCL_PIN = 34;

// SPI port
uint8_t const SS_PIN = 15;
uint8_t const MOSI_PIN = 17;
uint8_t const MISO_PIN = 18;
uint8_t const SCK_PIN = 16;

static const pin_map_t digitalPinMap[] = {
  {&DDRE, &PINE, &PORTE, 0},  // E0  0
  {&DDRE, &PINE, &PORTE, 1},  // E1  1
  {&DDRE, &PINE, &PORTE, 2},  // E2  2
  {&DDRE, &PINE, &PORTE, 3},  // E3  3
  {&DDRE, &PINE, &PORTE, 4},  // E4  4
  {&DDRE, &PINE, &PORTE, 5},  // E5  5
  {&DDRE, &PINE, &PORTE, 6},  // E6  6
  {&DDRE, &PINE, &PORTE, 7},  // E7  7
  
  {&DDRH, &PINH, &PORTH, 0},  // H0  8
  {&DDRH, &PINH, &PORTH, 1},  // H1  9
  {&DDRH, &PINH, &PORTH, 2},  // H2 10
  {&DDRH, &PINH, &PORTH, 3},  // H3 11
  {&DDRH, &PINH, &PORTH, 4},  // H4 12
  {&DDRH, &PINH, &PORTH, 5},  // H5 13
  {&DDRH, &PINH, &PORTH, 6},  // H6 14
  
  {&DDRB, &PINB, &PORTB, 0},  // B0 15
  {&DDRB, &PINB, &PORTB, 1},  // B1 16
  {&DDRB, &PINB, &PORTB, 2},  // B2 17
  {&DDRB, &PINB, &PORTB, 3},  // B3 18
  {&DDRB, &PINB, &PORTB, 4},  // B4 19
  {&DDRB, &PINB, &PORTB, 5},  // B5 20
  {&DDRB, &PINB, &PORTB, 6},  // B6 21
  {&DDRB, &PINB, &PORTB, 7},  // B7 22
  
  {&DDRH, &PINH, &PORTH, 7},  // H7 23
  
  {&DDRG, &PING, &PORTG, 3},  // G3 24
  {&DDRG, &PING, &PORTG, 4},  // G4 25
  
  {&DDRL, &PINL, &PORTL, 0},  // L0 26
  {&DDRL, &PINL, &PORTL, 1},  // L1 27
  {&DDRL, &PINL, &PORTL, 2},  // L2 28
  {&DDRL, &PINL, &PORTL, 3},  // L3 29
  {&DDRL, &PINL, &PORTL, 4},  // L4 30
  {&DDRL, &PINL, &PORTL, 5},  // L5 31
  {&DDRL, &PINL, &PORTL, 6},  // L6 32
  {&DDRL, &PINL, &PORTL, 7},  // L7 33
  
  {&DDRD, &PIND, &PORTD, 0},  // D0 34
  {&DDRD, &PIND, &PORTD, 1},  // D1 35
  {&DDRD, &PIND, &PORTD, 2},  // D2 36
  {&DDRD, &PIND, &PORTD, 3},  // D3 37
  {&DDRD, &PIND, &PORTD, 4},  // D4 38
  {&DDRD, &PIND, &PORTD, 5},  // D5 39
  {&DDRD, &PIND, &PORTD, 6},  // D6 40
  {&DDRD, &PIND, &PORTD, 7},  // D7 41
 
  {&DDRG, &PING, &PORTG, 0},  // G0 42
  {&DDRG, &PING, &PORTG, 1},  // G1 43
  
  {&DDRC, &PINC, &PORTC, 0},  // C0 44
  {&DDRC, &PINC, &PORTC, 1},  // C1 45
  {&DDRC, &PINC, &PORTC, 2},  // C2 46
  {&DDRC, &PINC, &PORTC, 3},  // C3 47
  {&DDRC, &PINC, &PORTC, 4},  // C4 48
  {&DDRC, &PINC, &PORTC, 5},  // C5 49
  {&DDRC, &PINC, &PORTC, 6},  // C6 50
  {&DDRC, &PINC, &PORTC, 7},  // C7 51
  
  {&DDRJ, &PINJ, &PORTJ, 0},  // J0 52
  {&DDRJ, &PINJ, &PORTJ, 1},  // J1 53
  {&DDRJ, &PINJ, &PORTJ, 2},  // J2 54
  {&DDRJ, &PINJ, &PORTJ, 3},  // J3 55
  {&DDRJ, &PINJ, &PORTJ, 4},  // J4 56
  {&DDRJ, &PINJ, &PORTJ, 5},  // J5 57
  {&DDRJ, &PINJ, &PORTJ, 6},  // J6 58
  
  {&DDRG, &PING, &PORTG, 2},  // G2 59
  
  {&DDRA, &PINA, &PORTA, 7},  // A7 60
  {&DDRA, &PINA, &PORTA, 6},  // A6 61
  {&DDRA, &PINA, &PORTA, 5},  // A5 62
  {&DDRA, &PINA, &PORTA, 4},  // A4 63
  {&DDRA, &PINA, &PORTA, 3},  // A3 64
  {&DDRA, &PINA, &PORTA, 2},  // A2 65
  {&DDRA, &PINA, &PORTA, 1},  // A1 66
  {&DDRA, &PINA, &PORTA, 0},  // A0 67
  
  {&DDRJ, &PINJ, &PORTJ, 7},  // J7 68
  
  {&DDRF, &PINF, &PORTF, 0},  // F0 69
  {&DDRF, &PINF, &PORTF, 1},  // F1 70
  {&DDRF, &PINF, &PORTF, 2},  // F2 71
  {&DDRF, &PINF, &PORTF, 3},  // F3 72
  {&DDRF, &PINF, &PORTF, 4},  // F4 73
  {&DDRF, &PINF, &PORTF, 5},  // F5 74
  {&DDRF, &PINF, &PORTF, 6},  // F6 75
  {&DDRF, &PINF, &PORTF, 7},  // F7 76
  
  {&DDRK, &PINK, &PORTK, 0},  // K0 77
  {&DDRK, &PINK, &PORTK, 1},  // K1 78
  {&DDRK, &PINK, &PORTK, 2},  // K2 79
  {&DDRK, &PINK, &PORTK, 3},  // K3 80
  {&DDRK, &PINK, &PORTK, 4},  // K4 81
  {&DDRK, &PINK, &PORTK, 5},  // K5 82
  {&DDRK, &PINK, &PORTK, 6},  // K6 83
  {&DDRK, &PINK, &PORTK, 7},  // K7 84
  
  {&DDRG, &PING, &PORTG, 5},  // G5 85
};


//MightyCore standard pinout
#elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \
|| defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__)\
|| defined(__AVR_ATmega324__) || defined(__AVR_ATmega324P__)\
|| defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega164P__)\
|| defined(__AVR_ATmega164A__) || defined(__AVR_ATmega32__)\
|| defined(__AVR_ATmega16__) || defined(__AVR_ATmega8535__) && defined(STANDARD_PINOUT)


// Two Wire (aka I2C) ports
uint8_t const SDA_PIN = 17;
uint8_t const SCL_PIN = 16;

// SPI port
uint8_t const SS_PIN = 4;		
uint8_t const MOSI_PIN = 5;	
uint8_t const MISO_PIN = 6;	
uint8_t const SCK_PIN = 7;	

static const pin_map_t digitalPinMap[] = {
  {&DDRB, &PINB, &PORTB, 0},  // B0  0
  {&DDRB, &PINB, &PORTB, 1},  // B1  1
  {&DDRB, &PINB, &PORTB, 2},  // B2  2
  {&DDRB, &PINB, &PORTB, 3},  // B3  3
  {&DDRB, &PINB, &PORTB, 4},  // B4  4
  {&DDRB, &PINB, &PORTB, 5},  // B5  5
  {&DDRB, &PINB, &PORTB, 6},  // B6  6
  {&DDRB, &PINB, &PORTB, 7},  // B7  7
  {&DDRD, &PIND, &PORTD, 0},  // D0  8
  {&DDRD, &PIND, &PORTD, 1},  // D1  9
  {&DDRD, &PIND, &PORTD, 2},  // D2 10
  {&DDRD, &PIND, &PORTD, 3},  // D3 11
  {&DDRD, &PIND, &PORTD, 4},  // D4 12
  {&DDRD, &PIND, &PORTD, 5},  // D5 13
  {&DDRD, &PIND, &PORTD, 6},  // D6 14
  {&DDRD, &PIND, &PORTD, 7},  // D7 15
  {&DDRC, &PINC, &PORTC, 0},  // C0 16
  {&DDRC, &PINC, &PORTC, 1},  // C1 17
  {&DDRC, &PINC, &PORTC, 2},  // C2 18
  {&DDRC, &PINC, &PORTC, 3},  // C3 19
  {&DDRC, &PINC, &PORTC, 4},  // C4 20
  {&DDRC, &PINC, &PORTC, 5},  // C5 21
  {&DDRC, &PINC, &PORTC, 6},  // C6 22
  {&DDRC, &PINC, &PORTC, 7},  // C7 23
  {&DDRA, &PINA, &PORTA, 0},  // A0 24
  {&DDRA, &PINA, &PORTA, 1},  // A1 25
  {&DDRA, &PINA, &PORTA, 2},  // A2 26
  {&DDRA, &PINA, &PORTA, 3},  // A3 27
  {&DDRA, &PINA, &PORTA, 4},  // A4 28
  {&DDRA, &PINA, &PORTA, 5},  // A5 29
  {&DDRA, &PINA, &PORTA, 6},  // A6 30
  {&DDRA, &PINA, &PORTA, 7}   // A7 31
};

//------------------------------------------------------------------------------

//MightyCore Bobuino pinout
#elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \
|| defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \
|| defined(__AVR_ATmega324__) || defined(__AVR_ATmega324P__) \
|| defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega164P__) \
|| defined(__AVR_ATmega164A__) || defined(__AVR_ATmega32__) \
|| defined(__AVR_ATmega16__) || defined(__AVR_ATmega8535__) && defined(BOBUINO_PINOUT)

// Two Wire (aka I2C) ports
uint8_t const SDA_PIN = 23;
uint8_t const SCL_PIN = 22;

// SPI port
uint8_t const SS_PIN = 10;
uint8_t const MOSI_PIN = 11;
uint8_t const MISO_PIN = 12;
uint8_t const SCK_PIN = 13;

static const pin_map_t digitalPinMap[] = {
  {&DDRD, &PIND, &PORTD, 0},  // D0 PD0
  {&DDRD, &PIND, &PORTD, 1},  // D1 PD1
  {&DDRD, &PIND, &PORTD, 2},  // D2 PD2
  {&DDRD, &PIND, &PORTD, 3},  // D3 PD3
  {&DDRB, &PINB, &PORTB, 0},  // D4 PB0
  {&DDRB, &PINB, &PORTB, 1},  // D5 PB1
  {&DDRB, &PINB, &PORTB, 2},  // D6 PB2
  {&DDRB, &PINB, &PORTB, 3},  // D7 PB3
  {&DDRD, &PIND, &PORTD, 5},  // D8 PD5
  {&DDRD, &PIND, &PORTD, 6},  // D9 PD6
  {&DDRB, &PINB, &PORTB, 4},  // D10 PB4
  {&DDRB, &PINB, &PORTB, 5},  // D11 PB5
  {&DDRB, &PINB, &PORTB, 6},  // D12 PB6
  {&DDRB, &PINB, &PORTB, 7},  // D13 PB7
  {&DDRA, &PINA, &PORTA, 7},  // D14 PA7
  {&DDRA, &PINA, &PORTA, 6},  // D15 PA6
  {&DDRA, &PINA, &PORTA, 5},  // D16 PA5
  {&DDRA, &PINA, &PORTA, 4},  // D17 PA4
  {&DDRA, &PINA, &PORTA, 3},  // D18 PA3
  {&DDRA, &PINA, &PORTA, 2},  // D19 PA2
  {&DDRA, &PINA, &PORTA, 1},  // D20 PA1
  {&DDRA, &PINA, &PORTA, 0}   // D21 PA0
  {&DDRC, &PINC, &PORTC, 0},  // D22 PC0
  {&DDRC, &PINC, &PORTC, 1},  // D23 PC1
  {&DDRC, &PINC, &PORTC, 2},  // D24 PC2
  {&DDRC, &PINC, &PORTC, 3},  // D25 PC3
  {&DDRC, &PINC, &PORTC, 4},  // D26 PC4
  {&DDRC, &PINC, &PORTC, 5},  // D27 PC5
  {&DDRC, &PINC, &PORTC, 6},  // D28 PC6
  {&DDRC, &PINC, &PORTC, 7},  // D29 PC7
  {&DDRD, &PIND, &PORTD, 4},  // D30 PD4
  {&DDRD, &PIND, &PORTD, 7},  // D31 PD7

};                       
                        



//------------------------------------------------------------------------------
static const uint8_t digitalPinCount = sizeof(digitalPinMap)/sizeof(pin_map_t);

uint8_t badPinNumber(void)
  __attribute__((error("Pin number is too large or not a constant")));

static inline __attribute__((always_inline))
  uint8_t getPinMode(uint8_t pin) {
  if (__builtin_constant_p(pin) && pin < digitalPinCount) {
    return (*digitalPinMap[pin].ddr >> digitalPinMap[pin].bit) & 1;
  } else {
    return badPinNumber();
  }
}
static inline __attribute__((always_inline))
  void setPinMode(uint8_t pin, uint8_t mode) {
  if (__builtin_constant_p(pin) && pin < digitalPinCount) {
    if (mode) {
      *digitalPinMap[pin].ddr |= 1 << digitalPinMap[pin].bit;
    } else {
      *digitalPinMap[pin].ddr &= ~(1 << digitalPinMap[pin].bit);
    }
  } else {
    badPinNumber();
  }
}
static inline __attribute__((always_inline))
  uint8_t fastDigitalRead(uint8_t pin) {
  if (__builtin_constant_p(pin) && pin < digitalPinCount) {
    return (*digitalPinMap[pin].pin >> digitalPinMap[pin].bit) & 1;
  } else {
    return badPinNumber();
  }
}
static inline __attribute__((always_inline))
  void fastDigitalWrite(uint8_t pin, uint8_t value) {
  if (__builtin_constant_p(pin) && pin < digitalPinCount) {
    if (value) {
      *digitalPinMap[pin].port |= 1 << digitalPinMap[pin].bit;
    } else {
      *digitalPinMap[pin].port &= ~(1 << digitalPinMap[pin].bit);
    }
  } else {
    badPinNumber();
  }
}
#endif  // Sd2PinMap_h

#elif defined (__CPU_ARC__)

#if defined (__ARDUINO_ARC__)
// Two Wire (aka I2C) ports
uint8_t const SDA_PIN = 18;
uint8_t const SCL_PIN = 19;

// SPI port
uint8_t const SS_PIN = 10;
uint8_t const MOSI_PIN = 11;
uint8_t const MISO_PIN = 12;
uint8_t const SCK_PIN = 13;

#endif	// Arduino ARC

#else
#error Architecture or board not supported.
#endif

#endif